﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TvTipper.Api;
using TvTipper.Entities;

namespace TvTipper.Core
{
    public class EntityManager
    {
        private IDictionary<LookupType, IList<LookupEntity>> m_lookups = new Dictionary<LookupType, IList<LookupEntity>>();
        private IDictionary<string, float> m_rankFactors;


        public bool RecommandationUpdated
        {
            get;
            set;
        }

        public void Initialize()
        {
            // preload lookups
            GetLookup(LookupType.Genere);
            GetLookup(LookupType.Role);

            // rank factors
            m_rankFactors = Services.DataAccessPortal.GetRankFactors();
        }

        public IList<LookupEntity> GetLookup(LookupType type)
        {
            IList<LookupEntity> lookups;
            if (m_lookups.TryGetValue(type, out lookups))
            {
                return lookups;
            }

            lookups = Services.DataAccessPortal.getLookupByKey(type);
            if (lookups == null)
            {
                return null;
            }

            m_lookups[type] = lookups;
            return lookups;
        }

        public IDictionary<string, float> RankFactors
        {
            get
            {
                return m_rankFactors;
            }

            set
            {
                Services.DataAccessPortal.SetRankFactors(value);
                m_rankFactors = value;
            }
        }
    }
}
